package com.jyy.prefabricated.listener;


import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.jyy.prefabricated.entity.StudentSignUpApply;
import com.jyy.prefabricated.enums.EducationBackgroundStatusEnum;
import com.jyy.prefabricated.vo.EnrollsProjectData;

import java.util.ArrayList;
import java.util.List;

public class EnrollsExcelListener extends AnalysisEventListener<EnrollsProjectData> {

    // 因为最终保存数据库的操作是在本类中实现，所以要添加一个属性，使用UserCreditRecordService里的CRUD方法

    private Integer excelNum = 0;
    private Integer successNum = 0;
    /**
     * 学员信息
     */
    List<StudentSignUpApply> studentDList = new ArrayList<>();

    /**
     * 无参构造
     */
    public EnrollsExcelListener() {
    }

    public List<StudentSignUpApply> getStudentDList() {
        return studentDList;
    }

    public void setStudentDList(List<StudentSignUpApply> studentDList) {
        this.studentDList = studentDList;
    }

    public Integer getExcelNum() {
        return excelNum;
    }

    public void setExcelNum(Integer excelNum) {
        this.excelNum = excelNum;
    }

    public Integer getSuccessNum() {
        return successNum;
    }

    public void setSuccessNum(Integer successNum) {
        this.successNum = successNum;
    }

    //easyExcel每次从Excel中读取一行数据就会调用一次invoke方法
    @Override
    public void invoke(EnrollsProjectData enrollsData, AnalysisContext analysisContext) {
        if (enrollsData != null && enrollsData.getIdCard() != null) {
            StudentSignUpApply studentSignUpApply = enrollsData.toStudentSignUpApply();
            if (enrollsData.getSex() != null) {
                if ("男".equals(enrollsData.getSex())) {
                    studentSignUpApply.setSex(1);
                }
                if ("女".equals(enrollsData.getSex())) {
                    studentSignUpApply.setSex(2);
                }
            }
            if (enrollsData.getEducationBackground() != null) {
                if ("小学".equals(enrollsData.getEducationBackground())) {
                    studentSignUpApply.setEducationBackground(EducationBackgroundStatusEnum.ONE.getValue());
                } else if ("初中".equals(enrollsData.getEducationBackground())) {
                    studentSignUpApply.setEducationBackground(EducationBackgroundStatusEnum.TEO.getValue());
                } else if ("高中".equals(enrollsData.getEducationBackground())) {
                    studentSignUpApply.setEducationBackground(EducationBackgroundStatusEnum.THREE.getValue());
                } else if ("职高".equals(enrollsData.getEducationBackground())) {
                    studentSignUpApply.setEducationBackground(EducationBackgroundStatusEnum.FOUR.getValue());
                } else if ("中专".equals(enrollsData.getEducationBackground())) {
                    studentSignUpApply.setEducationBackground(EducationBackgroundStatusEnum.FIVE.getValue());
                } else if ("大专".equals(enrollsData.getEducationBackground())) {
                    studentSignUpApply.setEducationBackground(EducationBackgroundStatusEnum.SIX.getValue());
                } else if ("本科".equals(enrollsData.getEducationBackground())) {
                    studentSignUpApply.setEducationBackground(EducationBackgroundStatusEnum.SEVEN.getValue());
                } else if ("硕士".equals(enrollsData.getEducationBackground())) {
                    studentSignUpApply.setEducationBackground(EducationBackgroundStatusEnum.EIGHT.getValue());
                } else {
                    studentSignUpApply.setEducationBackground(EducationBackgroundStatusEnum.Nine.getValue());
                }
            }
            studentDList.add(studentSignUpApply);
        }
    }

    //easyExcel在将Excel表中数据读取完毕后，最终执行此方法
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        //最后,如果size<BATCH_COUNT就在这里进行数据的处理

    }

}
